//
//  LcPhotoCenter.m
//  18Birdies
//
//  Created by weihuazhang on 2016/12/1.
//  Copyright © 2016年 Lc. All rights reserved.
//

#import "LcPhotoCenter.h"
@import Photos;

@implementation LcPhotoCenter

- (BOOL)authorizationNotDetermined {
  PHAuthorizationStatus photoAuthorStatus = [PHPhotoLibrary authorizationStatus];
  return photoAuthorStatus == PHAuthorizationStatusNotDetermined;
}

- (BOOL)authorized {
  PHAuthorizationStatus photoAuthorStatus = [PHPhotoLibrary authorizationStatus];
  return photoAuthorStatus == PHAuthorizationStatusAuthorized;
}

- (BOOL)requestAuthorization {
  __block BOOL accessGranted = NO;
  dispatch_semaphore_t sema = dispatch_semaphore_create(0);
  [PHPhotoLibrary requestAuthorization:^(PHAuthorizationStatus status) {
    accessGranted = status == PHAuthorizationStatusAuthorized;
    dispatch_semaphore_signal(sema);
  }];
  dispatch_semaphore_wait(sema, DISPATCH_TIME_FOREVER);
  return accessGranted;
}

@end
